﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;


    public class StringHelper
    {
 /// <summary>
    /// 字符串中文枚举
    /// </summary>
        public enum TransferedMeaningString_Type
        {
            String_Winform_or_Xamarin_Label换行 = 0,
            String_Winform_or_Xamarin_Textbox换行 = 1
        }
 public static string GetTransferedMeaningString(TransferedMeaningString_Type string_Type)
    {
        if (string_Type == TransferedMeaningString_Type.String_Winform_or_Xamarin_Label换行)
        {
            return "\n";
        }
        if (string_Type == TransferedMeaningString_Type.String_Winform_or_Xamarin_Textbox换行)
        {
            return "\r\n";
        }
   return "";
}


    public static string GetAccumulationString(string[] StringAccumulation, string Innertext, bool AppendLastInnertext)
    {
        string AccumulationString = "";
        for (int i = 0; i < StringAccumulation.Length; i++)
        {
            if (i == StringAccumulation.Length - 1)
            {
                if (AppendLastInnertext)
                {
                    AccumulationString = AccumulationString + StringAccumulation[i] + Innertext;
                    return AccumulationString;
                }
                else
                {
                    AccumulationString = AccumulationString + StringAccumulation[i];
                    return AccumulationString;
                }
            }
            else
            {
                AccumulationString = AccumulationString + StringAccumulation[i] + Innertext;

            }
        }
        return AccumulationString;

    }
    public static string GetAccumulationString(List<string> StringAccumulation,string Innertext,bool AppendLastInnertext)
        {
                string AccumulationString = "";
                for (int i = 0; i < StringAccumulation.Count; i++)
                {
                    if (i == StringAccumulation.Count - 1)
                    {
                        if (AppendLastInnertext)
                        {
                            AccumulationString = AccumulationString + StringAccumulation[i] + Innertext;
                            return AccumulationString;
                        }
                        else
                        {
                            AccumulationString = AccumulationString + StringAccumulation[i];
                            return AccumulationString;
                        }
                    }
                    else
                    {
                        AccumulationString = AccumulationString + StringAccumulation[i] + Innertext;

                    }
                }
                return AccumulationString;

        }
    public static string[] GetSplitString(string spitstring,string Innertext, bool ResultContainEmptyElement)
        {
            string[] sign = new string[1] { Innertext };
            if (ResultContainEmptyElement)
            {
                string[] split = spitstring.Split(sign, StringSplitOptions.None);
                return split;
            }
            else
            {
                string[] split = spitstring.Split(sign, StringSplitOptions.RemoveEmptyEntries);
                return split;
            }

        }

  public static List<string> GetSplitListString2(string spitstring, string Innertext, string Innertext2, bool ResultContainEmptyElement,List<string> replace_string)
    {
        string[] sign = new string[2] { Innertext, Innertext2 };
        if (ResultContainEmptyElement)
        {
            string[] split = spitstring.Split(sign, StringSplitOptions.None);
            for (int i = 0; i < split.Length; i++)
            {
                split[i] = split[i].ToLower();
                for (int j = 0; j < replace_string.Count; j++)
                {
                    split[i] = split[i].Replace(replace_string[j], "");
                }

            }
            return split.Distinct().ToList();
        }
        else
        {
            string[] split = spitstring.Split(sign, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < split.Length; i++)
            {
                split[i] = split[i].ToLower();
                for (int j = 0; j < replace_string.Count; j++)
                {
                    split[i] = split[i].Replace(replace_string[j], "");
                }

            }
            return split.Distinct().ToList();
        }

    }

    public static List<string> GetSplitListString(string spitstring, string Innertext, bool ResultContainEmptyElement)
    {
        string[] sign = new string[1] { Innertext };
        if (ResultContainEmptyElement)
        {
            string[] split = spitstring.Split(sign, StringSplitOptions.None);
            return split.ToList();
        }
        else
        {
            string[] split = spitstring.Split(sign, StringSplitOptions.RemoveEmptyEntries);
            return split.ToList();
        }

    }
    public static List<bool> LetStringtoBoolList(string strings)
    {
        List<bool> bools=new List<bool>();
        for (int i = 0; i < strings.Length; i++)
        {
            string a = strings.Substring(i,1);
            if (a == "1")
            {
                bools.Add(true);
            }
            else if (a == "0")
            {
                bools.Add(false);
            }
            else
            {
                bools.Clear();
                return bools;
            }

        }
        return bools;
    }

}